<template>
  <div>
      <el-form :model="sitedata" label-width="120px">
      <el-form-item label="站点标题">
        <el-input v-model="sitedata.name" />
      </el-form-item>
      <el-form-item label="站点副标题">
        <el-input v-model="sitedata.name" />
      </el-form-item>
      <el-form-item label="站点域名">
        <el-input v-model="sitedata.name" />
      </el-form-item>

      <el-form-item label="站点LOGO">
        <el-upload
          class="avatar-uploader"
          :action="`${path}/fileUploadAndDownload/upload`"
          :show-file-list="false"
          :on-success="handleAvatarSuccess"
          :before-upload="beforeAvatarUpload"
          :headers="header"
          list-type="picture-card"
          :on-preview="handlePictureCardPreview"
          :on-remove="handleRemove"
        >
          <img v-if="imageUrl" :src="imageUrl" class="avatar" />
          <el-icon v-else class="avatar-uploader-icon"><Plus /></el-icon>
        </el-upload>
      </el-form-item>

      <el-form-item label="站点关键字">
        <el-input v-model="sitedata.name" />
      </el-form-item>

      <el-form-item label="站点描述">
        <el-input v-model="sitedata.desc" type="textarea" />
      </el-form-item>
      <el-form-item label="站点备案">
        <el-input v-model="sitedata.name" />
      </el-form-item>

      <el-form-item label="站点模板">
        <el-select v-model="sitedata.region" placeholder="请选择">
          <el-option label="default" value="default" selected="selected" />
        </el-select>
      </el-form-item>

      <el-form-item label="统计代码">
        <el-input v-model="sitedata.desc" type="textarea" />
      </el-form-item>
      <el-form-item label="尾部信息">
        <el-input v-model="sitedata.desc" type="textarea" />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="onSubmit">提交</el-button>
        <el-button>取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script setup>
import { ref } from "vue";

  const sitedata = ref([])
  const imageUrl = ref([])
  const path = ref(import.meta.env.VITE_BASE_API)
  
  const handleAvatarSuccess = (
  response,
  uploadFile
) => {
  // console.log('token',uploadFile,response)
  imageUrl.value = response.data.file.url
}

const beforeAvatarUpload = (rawFile) => {
  if (rawFile.type !== 'image/jpeg' && rawFile.type !== 'image/png') {
    ElMessage.error('图片必须是PNG或JPG格式')
    return false
  } else if (rawFile.size / 1024 / 1024 > 2) {
    ElMessage.error('图片大小不能大于 2MB!')
    return false
  }
  return true
}

</script>

<style lang="scss">

</style>